package me.zhengjie.poemmanager.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.dailyPoem.service.PoemRecommendService;
import me.zhengjie.poemmanager.domain.Query;
import me.zhengjie.poemmanager.domain.vo.QueryCriteria;
import me.zhengjie.poemmanager.service.QueryService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hwl
 * @date 2024-12-06
 **/

@RestController
@RequiredArgsConstructor
@Api(tags = "查询")
@RequestMapping("/api/query")
public class QueryController {
    private final QueryService queryService;

    private final PoemRecommendService poemRecommendService;

    @Log("综合查询")
    @ApiOperation("综合查询")
    @GetMapping
    @AnonymousAccess
    public List<QueryCriteria> queryAllByTitle(@RequestParam String title){
        return queryService.queryAllByTitle(title);
    }
    @GetMapping("paged")
    @Log("根据关键字查询")
    @ApiOperation("根据关键字查询")
    @AnonymousAccess
    public ResponseEntity<PageResult<Query>> queryInfo(String keyWord,
                                                       @RequestParam(defaultValue = "1") int current,
                                                       @RequestParam(defaultValue = "20") int size  ){
        Page<Object> page = new Page<>(current,size);
        return new ResponseEntity<>(poemRecommendService.queryInfoPaged(keyWord,page), HttpStatus.OK);
    }
}
